package com.baomidou.ant.controller;


import com.baomidou.ant.common.Result;
import com.baomidou.ant.entity.ExchangeList;
import com.baomidou.ant.entity.PointsStore;
import com.baomidou.ant.entity.UserBag;
import com.baomidou.ant.service.IExchangeListService;
import com.baomidou.ant.service.IPointsStoreService;
import com.baomidou.ant.service.IUserBagService;
import com.baomidou.ant.vo.Request.RequestDeleteVo;
import com.baomidou.ant.vo.Request.RequestExchangeListOfAdminVo;
import com.baomidou.ant.vo.Request.RequestExchangeListVo;
import com.baomidou.ant.vo.Request.RequestUseGoodsVo;
import com.baomidou.ant.vo.Response.ResponseExchangeListOfAdminVo;
import com.baomidou.ant.vo.Response.ResponseExchangeListVo;
import com.baomidou.ant.vo.Response.ResponseMyBagListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/exchange-list")
public class ExchangeListController {
    @Autowired
    private IExchangeListService exchangeListService;
    //展示兑换清单接口
    @PostMapping("/list")
    public Result list(@RequestBody RequestExchangeListVo requestExchangeListVo){
        IPage<ResponseExchangeListVo> iPage=exchangeListService.list(requestExchangeListVo);
        return Result.getSuccess().setData(iPage);
    }

    //后台管理订单纪录
    @PostMapping("/listOfAdmin")
    public Result listOfAdmin(@RequestBody RequestExchangeListOfAdminVo requestExchangeListOfAdminVo){
        IPage<ResponseExchangeListOfAdminVo> iPage=exchangeListService.listOfAdmin(requestExchangeListOfAdminVo);
        return Result.getSuccess().setData(iPage);
    }

    //通过id
    @DeleteMapping("/delete/{exchangeListId}")
    public Result delete(@PathVariable Integer exchangeListId){
        if(exchangeListService.removeById(exchangeListId)){
            return Result.getSuccess().setMsg("删除成功!");
        }else {
            return Result.getFailure().setMsg("删除失败!");
        }
    }

    //批量
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody RequestDeleteVo requestDeleteVo){
        List<Integer> ids= Arrays.asList(requestDeleteVo.getIds());
        if(ids.size()>0&&exchangeListService.removeByIds(ids)){
            return Result.getSuccess().setMsg("删除成功");
        }else{
            return Result.getFailure().setMsg("请勾选要删除的项！");
        }
    }


}
